<template>
  <div class="menuTab">
    <el-aside width="200px">
      <el-menu
          router
          default-active="2"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#2578b6"
          text-color="#fff"
          active-text-color="#ffd04b">

        <!-- 导航树 -->
        <template v-for="(item, index) in menus" :key="index">
          <el-sub-menu :index="index + ''" v-if="!item.hidden">
            <template #title>
              <i :class="item.iconClass"></i><!-- style="margin-left: 5px" -->
              <span>{{ item.name }}</span>
            </template>

            <el-menu-item-group v-for="(child, index) in item.children" :key="index">
              <el-menu-item :index="child.path">
                <i :class="child.iconClass"></i>
                <span>{{ child.name }}</span>
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
        </template>

      </el-menu>
    </el-aside>
  </div>
</template>

<script>
    export default {
      name: "MenuTab",
      data () {
        return {
          menus: [],
        }
      },
      created () {
        console.log(this.$router.options.routes);
        this.menus = [...this.$router.options.routes];
      },
      methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
      }
    }
</script>

<style scoped lang="scss">
.menuTab {
  .el-aside {
    height: 100%;
    .el-menu {
      height: 100%;
    }
    .el-sub-menu .el-sub-item {
      min-width: 0;
    }
  }
}
</style>